 <meta charset="utf-8">
<script src="js/jquery.js"> </script>	
<script> $(function(){
	$("#percent").change(function(){
		$("#depositprice").val(($("#allprice").val()*$("#percent").val())/100);
		});
	});</script>	
<link rel="stylesheet" href="css/csstb.css" type="text/css" media="screen" />
<form action="Javascript:insertdeli();" name="deli_pop" id="deli_pop" method="post">
<?php
require("db/connect.php");
require("prename.php");
$sql="select cus_title,cus_name,cus_lastname,SUM(qty*pro_price) as sumprice from orders,cart,product,customer
 where orders.orders_id=cart.orderid and cart.pro_id=product.pro_id and orders.cus_id=customer.cus_id and orders_id=".$_GET["order"]."";
$query=mysql_query($sql);
$result=mysql_fetch_array($query);

 ?>
 <style>
 body {
	 
    /*background-image :url("img/pyk.jpg");
    background-repeat: no-repeat;
    background-position:top;*/
}
</style>
 <div align="center"><img src="img/pyk.JPG"  width="330" height="240" /></div>
  <table width="516" border="10" style="border-color:#3F3">
    <tr>
      <td width="198">เลขที่ใบสั่งซื้อ</td>
      <td width="159" colspan="3"><?php echo $_GET["order"] ?></td>
     
    </tr>
    <tr>
      <td height="27">ผู้สั่งซื้อ</td>
      <td colspan="3"><?php echo (prename($result["cus_title"])."".$result["cus_name"])." ".$result["cus_lastname"]?></td>

    </tr>
      <tr>
      <td height="27">จำนวนเงินทั้งหมด</td>
      <td colspan="3">
        <label for="textfield"></label>
       <input name="allprice" type="number" id="allprice" value="<?php echo $result["sumprice"]  ?>" disabled="disabled" />บาท</td>
    </tr>
      <tr>
      <td height="27">จำนวนเงินมัดจำขั้นต่ำ</td>
      <td colspan="3">
        <label for="textfield"></label>
       <input name="sumprice" type="number" id="sumprice" value="<?php echo ($result["sumprice"]*50)/100  ?>" disabled="disabled" />บาท</td>
    </tr>
     <tr>
      <td height="27">จำนวนเงินมัดจำ</td>
      <td colspan="3"><?php  ?>
        <label for="textfield"></label>
       <input name="depositprice"  type="number" id="depositprice"  placeholder="กรอกจำนวนเงินที่ต้องการมัดจำ" />
     
   มัดจำตาม %
        <select name="percent" id="percent">
          <option value="50">50</option>
          <option value="60">60</option>
          <option value="70">70</option>
          <option value="80">80</option>
          <option value="90">90</option>
          <option value="100">100</option>
       </select></td>

    </tr>
    <tr>
      <td height="95" style="text-align:left;vertical-align:top">รายละเอียดสถานที่จัดส่ง</td>
      <td colspan="3"><label for="deli_addr"></label>
      <textarea name="deli_addr" id="deli_addr" cols="45" rows="5"></textarea></td>
    </tr>
  </table>
  <p align="center">
    <input type="submit" name="button" id="button" value="บันทึกการวางเงินมัดจำ">
    <input type="button" name="button2" id="button2" value="ยกเลิกการวางเงินมัดจำ" onClick="window.close();">
  </p>
  <script>
		 
		 function insertdeli(){
			 if($("#depositprice").val()<=$("#allprice").val()){
				 if($("#depositprice").val()<=$("#sumprice").val()){
					 var statusorder;
					 if($("#depositprice").val()==$("#allprice").val())  { statusorder="011";}
					 else{ statusorder="001";}
			 $.ajax({
				 url:'insert_deli.php',
				 data:$("#deli_pop").serialize()+"&statusorder="+statusorder+"&order=<?php echo $_GET["order"] ?>",
				 type:"POST",
				 success: function(msg){
					 alert("อัพเดทสถานะการจัดส่งเสร็จสิ้น");
					 //console.log(msg);
					 if (window.opener != null && !window.opener.closed) {
               window.opener.location.reload();
				window.close();
          			  }
	 					window.onbeforeunload = RefreshParent;
						 }
				 });}else{
					 alert("เงินมัดจำน้อยกว่าที่กำหนด");
					 }
				 }else{
					 alert("เงินมัดจำเกินกว่าที่กำหนด");
					 }
			 }
  </script>
</form>